
// sudo apt-get install libcurl4-openssl-dev
// gcc -o post_request post_request.c -lcurl


#include <stdio.h>
#include <curl/curl.h>

int main(void) {
    CURL *curl;
    CURLcode res;

    // 目标URL
    const char *url = "http://2.2.2.2/ac_portal/login.php";

    // POST请求的数据
    const char *post_data = "opr=pwdLogin&userName=bean.wang%40quectel.com&pwd=17bcaff7e338bfa00aff&auth_tag=1735537610&rememberPwd=1";

    // 初始化libcurl
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();

    if(curl) {
        // 设置URL
        curl_easy_setopt(curl, CURLOPT_URL, url);

        // 设置POST请求和数据
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);

        // 发送请求并获取响应
        res = curl_easy_perform(curl);

        // 检查请求是否成功
        if(res != CURLE_OK) {
            fprintf(stderr, "请求失败: %s\n", curl_easy_strerror(res));
        } else {
            // 打印响应内容
            long response_code;
            curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
            printf("响应状态码: %ld\n", response_code);
        }

        // 清理
        curl_easy_cleanup(curl);
    }

    // 全局清理
    curl_global_cleanup();
    return 0;
}


